package com.ehotting.edsta.caeu.domain;

import lombok.Data;

@Data
public class CustomResponse<T> {

    private boolean success;
    private int errorCode;
    private String message;
    private T data;

    public static <T> CustomResponse<T> success() {
        return restResult(null, true, 0, "操作成功");
    }

    public static <T> CustomResponse<T> success(T data) {
        return restResult(data, true, 0, "操作成功");
    }

    public static <T> CustomResponse<T> fail() {
        return restResult(null, false, 2001, "操作失败");
    }

    public static <T> CustomResponse<T> fail(String msg) {
        return restResult(null, false, 2001, msg);
    }

    private static <T> CustomResponse<T> restResult(T data, boolean success, int code, String msg) {
        CustomResponse<T> apiResult = new CustomResponse<>();
        apiResult.setSuccess(success);
        apiResult.setErrorCode(code);
        apiResult.setData(data);
        apiResult.setMessage(msg);
        return apiResult;
    }
}